package com.wgj.android.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wgj.android.R;
import com.wgj.android.entity.Message;
import com.wgj.android.entity.NewHistory;
import com.wgj.android.utils.DateUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * ========================================
 * 作    者： 佳爱网络有限公司(wwww.jiaailove.com)
 * 版    本： 1.0
 * 创建日期： 2017/12/14
 * 描    述：
 * 修订历吏：
 * =========================================
 */
public class MessageContentAdapter extends RecyclerView.Adapter<MessageContentAdapter.MyViewHolder> {
    private List<Message> messages;
    private Context context;
    private LayoutInflater inflater;
    public MessageContentAdapter(Context context , List messages){
        this.context = context;
        if(messages==null){
            messages = new ArrayList<NewHistory>();
        }
        this.messages=messages;
        this.inflater = LayoutInflater.from(context);

    }


    @Override
    public MessageContentAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_message_disc,null);
        return new MessageContentAdapter.MyViewHolder(view);

    }

    @Override
    public void onBindViewHolder(MessageContentAdapter.MyViewHolder holder, int position) {

       if(messages.get(position).getType()==0){
           holder.type.setText("系统消息");
       }else if(messages.get(position).getType()==1){
           holder.type.setText("我的钱包");
       }else if(messages.get(position).getType()==2){
           holder.type.setText("订单和提现");
       }
        holder.content.setText(messages.get(position).getContent());
        holder.time.setText( DateUtils.dateForm(messages.get(position).getCreateTime()));

    }

    @Override
    public int getItemCount() {
        return messages.size();
    }

    public class MyViewHolder extends  RecyclerView.ViewHolder{
        private TextView type;
        private TextView content;
        private TextView time;

        public MyViewHolder(View view) {
            super(view);
            type = view.findViewById(R.id.type);
            content = view.findViewById(R.id.content);
            time = view.findViewById(R.id.time);
        }

    }

}